/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAOImpl;

import Exception.DBConnectionException;
import POJO.Classes;
import Util.DBUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class ClassesImpl extends BaseImpl {

    @Override
    public boolean insert(Object obj) {
        boolean result = false;
        
        try{
            Connection con =  DBUtils.getConnection();
            
            String query = "INSERT INTO [dbo].[Classes](name,description)VALUES(?,?)";
            
            PreparedStatement pstmt = con.prepareStatement(query);
            
            Classes classObj = null;
            if(obj instanceof Classes  ){
                 classObj = (Classes)obj;
            }
            if(classObj != null){
                pstmt.setString(1, classObj.getName());
                pstmt.setString(2, classObj.getDescription());
                
            }
            else{
                return false;
            }
            
            //execute
            int effectedRows =  pstmt.executeUpdate();
            
            if(effectedRows > 0){
                result = true;
            }
            else{
                result = false;
            }
            
        }
        catch (SQLException ex) {
        
        }
        catch(DBConnectionException dbException){
            
        }
        
        return result;
    }
    
}
